package com.agent.util;

import lombok.extern.slf4j.Slf4j;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.util.Calendar;
import java.util.Date;
@Slf4j
public class DateUtil {

    public static final String DATE_FORMAT = "yyyy-MM-dd";
    public static final String DATE_TIME_FORMAT = "yyyy-MM-dd HH:mm:ss";
    private static final SimpleDateFormat date_Time_Format = new SimpleDateFormat(
            DATE_TIME_FORMAT);


    public static Date parseDate(String dateStr, String pattern) {
        SimpleDateFormat df = new SimpleDateFormat(pattern);
        try {
            return df.parse(dateStr);
        } catch (ParseException e) {
           log.error("com.agent.util.DateUtil.parseDate error|",e);
        }
        return null;
    }

    /**
     * 是否工作日   周一到周五 17.30之后   9点之前
     * @return
     */
    public static boolean isWorkDate(){
        Date date = new Date();
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        int week = calendar.get(Calendar.DAY_OF_WEEK);
        if((date.getHours() == 17 && date.getMinutes() >= 30) || date.getHours()>17 || date.getHours()<9 || week == 1 || week ==7){
            return false;
        }
        return true;
    }

    public static long diffSecond(Date beginDate,Date now){
        return (now.getTime()-beginDate.getTime())/1000;
    }

}
